package com.closer.server.biz.organization.service.impl;

import com.closer.server.support.exception.ErrorCode;
import com.closer.server.support.exception.ThrowUtils;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.closer.server.biz.organization.entity.OrganizationMember;
import com.closer.server.mapper.organization.OrganizationMemberMapper;
import com.closer.server.biz.organization.service.OrganizationMemberService;
import org.springframework.stereotype.Service;

/**
 * 组织成员表 服务层实现。
 *
 * @author closer
 */
@Service
public class OrganizationMemberServiceImpl extends ServiceImpl<OrganizationMemberMapper, OrganizationMember>  implements OrganizationMemberService{

    @Override
    public long getMemberCounts(Long organizationId) {
        return this.mapper.getMemberCount(organizationId);
    }

    @Override
    public long getId(Long memberId) {
        return this.mapper.getId(memberId);
    }

    @Override
    public long getEarliestMember(Long organizationId) {
        var result = this.mapper.getEarliestMember(organizationId);
        ThrowUtils.throwIf(result==null, ErrorCode.OPERATION_ERROR,"组织成员不存在");
        return result.getUserId();
    }
}
